<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 下午 4:31
 */
namespace app\blog\controller;
use app\blog\model\GoodsbackupModel as bc;
use cmf\controller\AdminBaseController;

class GoodsbackupController extends AdminBaseController{
    /**
     * 类别列表页面
    */
    public function _initialize()
    {
        parent::_initialize();
        $this->bc=new bc();
    }

    public function index(){
        $param = $this->request->param('state_name');
        $session=$this->bc->session();
        $shopid=$session['id'];
        //获取商品所有商品类别
        $rest       = $this->bc->index($param);
        $rest->appends(['shop_id'=>$shopid,'state_name'=>$param]);
        $this->assign('data',$rest);
        $this->assign('page',$rest->render());
        return $this->fetch('backup/index');
    }
    /**
     * 类别添加页面
    */
    public function add(){
        return $this->fetch('backup/add');
    }
    /**
     * 类别添加操作
    */
    public function addPost(){
        $date       = $this->request->param();
        $rest       = $this->bc->add($date);
        if($rest != false){
            $this->success('添加成功！','goodsbackup/index');
        }else{
            $this->error('添加失败');
        }

    }
    /**
     * 类别修改页面
    */
    public function detail(){
        //根据id获取该条类别信息
        $array          = $this->request->param();
        $where['id']=$array['id'];
        $rest        = $this->bc->getGcone($where);
        $this->assign('data',$rest);
        return $this->fetch('backup/detail');
    }
    /**
     * 类别修改操作
    */
    public function detailPost(){
        $date        = $this->request->param();
        $where       = array();
        $where['id'] = $date['id'];
        $data['state_name']=$date['state_name'];
        $rest        = $this->bc->detail($where,$data);
        if($rest != false){
            $this->success("操作成功！",url("goodsbackup/index"));
        }else{
            $this->error('操作失败');
        }
    }
    /**
     * 类别删除操作
    */
    public function del(){
        $date        = $this->request->param();
        $rest        = $this->bc->del($date);
        if($rest['num'] != 0){
            $this->success($rest['con'],url("goodsbackup/index"));
        }else{
            $this->error($rest['con'],url("goodsbackup/index"));
        }
    }
    /*禁用启用功能*/
    public function upStatus(){
        $date        = $this->request->param();
        $where       = array();
        $where['id'] = $date['id'];
        $date['status']=$date['status'];
        $rest        = $this->bc->detail($where,$date);
        if($rest != false){
            $this->success("操作成功！",url("goodsbackup/index"));
        }else{
            $this->error('操作失败',url("goodsbackup/index"));
        }
    }
}